/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow-x: hidden;
}

/* Container setup for iframe compatibility */
.container {
    width: 100%;
    height: 550px; /* Increased height for better graph display */
    max-width: 100%;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Detect if opened in new tab */
@media (min-height: 700px) {
    .container {
        height: 90vh;
    }
}

/* Top bar with level, score, and challenge */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    color: white;
    font-size: 0.9em;
    flex-shrink: 0;
}

.level-display, .score-display {
    font-weight: bold;
    background: rgba(255,255,255,0.2);
    padding: 4px 8px;
    border-radius: 12px;
}

.challenge-display {
    flex: 1;
    text-align: center;
    font-size: 0.85em;
    padding: 0 10px;
}

/* Main content area with dual panels */
.main-content {
    display: flex;
    flex: 1;
    gap: 10px;
    padding: 10px;
    min-height: 0;
}

.graph-panel, .algebra-panel {
    flex: 1;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.panel-title {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 8px;
    text-align: center;
    font-size: 0.9em;
    cursor: help;
}

/* Improved graph canvas styling - no compression */
#graph-canvas {
    width: 100%;
    max-width: 400px;
    height: auto;
    aspect-ratio: 1;
    border: 2px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: crosshair;
    margin: 0 auto;
    display: block;
}

.intersection-info {
    margin-top: 8px;
    text-align: center;
    font-weight: bold;
    color: #e74c3c;
    font-size: 0.9em;
}

/* Algebra panel content */
.equations-display {
    background: white;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    border-left: 4px solid #3498db;
}

.equation {
    font-family: 'Courier New', monospace;
    font-size: 1.1em;
    margin: 5px 0;
    padding: 4px;
    border-radius: 3px;
    transition: background-color 0.3s;
}

.equation:hover {
    background: #ecf0f1;
}

/* Manual solution input section */
.manual-solution {
    background: white;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    border-left: 4px solid #27ae60;
}

.solution-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}

.solution-input-group label {
    min-width: 30px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.solution-input-group input {
    flex: 1;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    text-align: center;
}

#check-manual {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

#check-manual:hover {
    background: #229954;
}

.solution-steps {
    flex: 1;
    background: white;
    padding: 10px;
    border-radius: 6px;
    border-left: 4px solid #e74c3c;
    overflow-y: auto;
}

.step-title {
    font-weight: bold;
    margin-bottom: 8px;
    color: #2c3e50;
}

#steps-content {
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
    white-space: pre-line;
}

/* Controls panel - modified for whole numbers only */
.controls-panel {
    padding: 10px 15px;
    background: #ecf0f1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    flex-shrink: 0;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
}

.control-group label {
    min-width: 60px;
    font-weight: 500;
    cursor: help;
}

.control-group input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.control-group input[type="number"] {
    width: 60px;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-size: 0.85em;
}

/* Action panel */
.action-panel {
    display: flex;
    gap: 10px;
    padding: 10px 15px;
    background: #f8f9fa;
    flex-shrink: 0;
}

.action-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    background: #95a5a6;
    color: white;
    min-height: 36px;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.action-btn.primary {
    background: #3498db;
}

.action-btn.primary:hover {
    background: #2980b9;
}

/* Feedback panel */
.feedback-panel {
    padding: 8px 15px;
    background: #2ecc71;
    color: white;
    text-align: center;
    font-weight: 500;
    transform: translateY(100%);
    transition: transform 0.3s;
    flex-shrink: 0;
}

.feedback-panel.show {
    transform: translateY(0);
}

.feedback-panel.error {
    background: #e74c3c;
}

.feedback-panel.warning {
    background: #f39c12;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #3498db;
    color: white;
    border-radius: 8px 8px 0 0;
}

.modal-header h3 {
    margin: 0;
}

.close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 20px;
    line-height: 1.6;
}

.modal-footer {
    padding: 15px 20px;
    text-align: right;
    border-top: 1px solid #eee;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        gap: 8px;
        padding: 8px;
    }
    
    .controls-panel {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px 10px;
    }
    
    .control-group {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .control-group label {
        min-width: 50px;
        font-size: 0.8em;
    }
    
    .action-panel {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
    }
    
    .action-btn {
        min-width: 80px;
        font-size: 0.85em;
        padding: 6px 10px;
    }
    
    #graph-canvas {
        max-width: 300px;
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {
    .action-btn {
        min-height: 44px;
        font-size: 1em;
    }
    
    .control-group input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .control-group input[type="number"] {
        min-height: 36px;
        font-size: 1em;
    }
}

/* Animation classes */
.highlight {
    animation: pulse 0.6s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}